package com.xianggu.designMode.strategy;

public class Client {
    public static void main(String[] args) {
        // 获取支付策略（通过工厂+单例模式）
        PaymentStrategy alipay = PaymentStrategyFactory.getStrategy("alipay");
        PaymentStrategy wechat = PaymentStrategyFactory.getStrategy("wechat");

        // 创建支付上下文
        PaymentContext context1 = new PaymentContext(alipay);
        context1.executePayment(100.0);  // 使用支付宝支付：100.0元

        PaymentContext context2 = new PaymentContext(wechat);
        context2.executePayment(200.0);  // 使用微信支付：200.0元

        // 验证单例模式
        PaymentStrategy alipay2 = PaymentStrategyFactory.getStrategy("alipay");
        System.out.println("alipay == alipay2: " + (alipay == alipay2));  // 输出：true
    }
}